package com.xhorse.lockplatform.manage.controller;

import com.xhorse.lockplatform.comm.mvc.AbstractCallbackController;
import com.xhorse.lockplatform.service.JpushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("jpush")
public class JpushController extends AbstractCallbackController {

    @Autowired
    private JpushService jpushService;

    @RequestMapping("/hdwpush")
    public String hdwpush() {
        return "jpush/hdwpush";
    }

    @RequestMapping("/customPush")
    public String customPush() {
        return "jpush/customPush";
    }

    /**
     * 固件升级消息推送
     *
     * @param regionId 推送的地区用户
     * @return
     */
    @RequestMapping(value = "/hardwareInfoPush", method = RequestMethod.POST)
    @ResponseBody
    public void hardwareInfoPush(HttpServletResponse response, int regionId) throws Exception {
        jpushService.hardwareInfoPush(regionId);
        simpleSuccess(response);
    }

    /**
     * 自定义推送消息
     *
     * @param infoList
     * @param languageIdList
     * @return
     */
    @RequestMapping(value = "customPushInfo", method = RequestMethod.POST)
    @ResponseBody
    public void customPushInfo(HttpServletResponse response,
                               @RequestParam("info") String[] infoList,
                               @RequestParam("languageId") int[] languageIdList) throws Exception {
        jpushService.customPushInfo(infoList, languageIdList);
        simpleSuccess(response);
    }

}
